﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace DAO
{

	public class CategoryDAO:IData<Category> 
 	{
		public CategoryDAO(String myconnecString) : base(myconnecString) { }

		public override int OnSubmit(Category item, int t) {
			 return connec.ExecuteNonQuery("sp_Category", CommandType.StoredProcedure,new SqlParameter("@flag", t),
				 new SqlParameter("@" + Category.c_id, item.id), new SqlParameter("@" + Category.c_name, item.name),
				 new SqlParameter("@" + Category.c_create_on, item.create_on), new SqlParameter("@" + Category.c_orderId, item.orderId)); 
		}

		public override Category GetItem(IDataReader dr)
		{
			Category obj = new Category();
			obj.id = Convert.ToInt64(dr[Category.c_id]);
			obj.name = Convert.ToString(dr[Category.c_name]);
			obj.create_on = Convert.ToDateTime(dr[Category.c_create_on]);
			obj.orderId = Convert.ToInt32(dr[Category.c_orderId]);
			return obj;
		}

		public override List<Category> GetAll()
		{
			return GetAll("select * from " + Category.b_Category, CommandType.Text);
		}

		public override Category GetItemById(object id)
		{
			throw new NotImplementedException();
		}

	}

 }
